#[test]
pub fn fold_test() {
    let a = [5, 6, 7, 8, 9, 10];
    // 计数，n为当前累加器，忽略迭代器的条目内容，可理解为计数
    assert_eq!(a.iter().fold(0, |n, _| n + 1), 6);
    // 求和，对列表的数字进行累加
    assert_eq!(a.iter().fold(0, |n, i| n + i), 45);
    // 乘积，累乘，注意，初始值应为1，不能为0了
    assert_eq!(a.iter().fold(1, |n, i| n * i), 151200);
    // 最大值
    assert_eq!(a.iter().cloned().fold(i32::MIN, std::cmp::max), 10);
}

#[test]
fn fold_test2(){
    let a = ["Pack", "my", "box", "with", "five", "dozen", "liquor", "jugs"];
    let pangram = a.iter().fold(String::new(), |s, w| s + w + " ");
    let data = a.join(" ");
    // assert_eq!(pangram, "Pack my box with five dozen liquor jugs ");
    assert_eq!(pangram, data + " ");
}

// #[test]
// fn try_fold_test(){
//     let stdin = std::io::stdin();
//     let sum = stdin.lock()
//         .lines()
//         .try_fold(0,|sum,line|->Result<u64,Box<dyn Error>> {
//             Ok(sum + u64::from_str(&line?.trim())?)
//         })?;
//     println!("{}", sum);
// }

